﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using S.Breeding.Api.Application.Command.BodyMeasureCommand;
using S.Breeding.Api.Application.Command.ConditionMeasureCommand;
using S.Breeding.Api.Application.Command.SheepWeighCommand;
using S.Breeding.Domain;

namespace S.Breeding.Api.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BreedingController : ControllerBase
    {
        private readonly IMediator mediator;
        public BreedingController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        #region 羊只称重
        /// <summary>
        /// 新增羊只称重
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddSheepWeigh(SheepWeighCreateCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = "宗介";
            request.CreateDate = DateTime.Now;
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除羊只称重
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DelSheepWeight([FromQuery] SheepWeighDeleteCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }
        /// <summary>
        /// 修改羊只称重
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdSheepWeight(SheepWeighUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateBy = "波妞";
            request.UpdateDate = DateTime.Now;
            return await mediator.Send(request);
        }

        /// <summary>
        /// 羊只称重批量删除
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> BatchSheepWeight([FromQuery]SheepWeighBatchCommand request, CancellationToken cancellationToken)
        {
            return Ok(await mediator.Send(request));
        }        
        #endregion

        #region 体尺测定
        /// <summary>
        /// 新增体尺测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddBodyMeasure(BodyMeasureCreateCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = "海绵宝宝";
            request.CreateDate= DateTime.Now;
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改体尺测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdBodyMeasure(BodyMeasureUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateBy = "派大星";
            request.UpdateDate = DateTime.Now;
            return await mediator.Send(request);
        }
        /// <summary>
        /// 单个删除体尺测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DelBodyMeasure([FromQuery]BodyMeasureDeleteCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量删除体尺测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> BatchBodyMeasure([FromQuery]BodyMeasureBatchCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 品相测定
        /// <summary>
        /// 新增品相测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> AddConditionMeasure(ConditionMeasureCreateCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = "宠儿";
            request.CreateDate = DateTime.Now;
            request.IsDel = false;
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除品相测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<int> DelConditionMeasure([FromQuery] ConditionMeasureDeleteCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 批量删除品相测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> BatchConditionMeasure([FromQuery]ConditionMeasureBatchCommand request, CancellationToken cancellationToken)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改品相测定
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateConditionMeasure(ConditionMeasureUpdateCommand request, CancellationToken cancellationToken)
        {
            request.UpdateBy = "念旧";
            request.UpdateDate = DateTime.Now;
            return await mediator.Send(request);
        }
        #endregion
    }
}
